'''
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with self work for additional information
 * regarding copyright ownership.  The ASF licenses self file
 * to you under the Apache License, Version 2.0 (the
 * "License") you may not use self file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http:#www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
'''
from base.graph.BlankNodeId import BlankNodeId

#import org.apache.jena.graph.BlankNodeId;

'''
 * System id for an anonymous node.
 * <p>
 * Blank nodes have identity (:@code .equalstells them apart)
 * but have no web-visible external stable identifier like a URI.
 * <p>
 * The Jena API has traditionally had:@code AnonId
 * in the RDF API.:@link BlankNodeIdis the SPI equivalent and databases
 * that need a persistent identifier across JVM instances use that for blank nodes.
 *
 * <p>This id is guaranteed to be unique on self machine.</p>
'''

class AnonId:

    # param
    # result static AnonId
    def create(self):
        return AnonId()
    

    # param String id
    # result static AnonId
    def createById(self, id):
        return AnonId(id)
    
    def __init__(self, id):
        if isinstance(id, str):
            self.blankNodeId = BlankNodeId.create(id)
        else:
            self.blankNodeId = id


    # param
    # result String
    def getLabelString(self):
        return self.blankNodeId.getLabelString()
    

    '''
     * Return the system BlankNodeId
    '''
    # param 
    # result BlankNodeId
    def getBlankNodeId(self):
        return self.blankNodeId
    

    # @Override
    # param 
    # result String
    def toString(self):
        return self.blankNodeId.toString()
    

    # @Override
    # param 
    # result int
    def hashCode(self):
        prime = 31
        result = 1
        result = prime * result + (0 if (self.blankNodeId is None) else self.blankNodeId.hashCode())
        return result
    

    # @Override
    # param Object obj
    # result boolean
    def equals(self, obj):
        if (self == obj):
            return True
        if (obj is None):
            return False
        if not isinstance(obj, AnonId):
            return False
        other = obj
        if (self.blankNodeId is None):
            if (other.blankNodeId is not None):
                return False
        elif (not self.blankNodeId.equals(other.blankNodeId)):
            return False
        return True
    

